# Maintainer: Diego Sogari <diego.sogari@falker.com.br>

_realname=ceres-solver
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.0
pkgrel=2
pkgdesc="A large scale non-linear optimization library (mingw-w64)"
arch=('any')
url="http://ceres-solver.org/"
license=('New BSD license')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-eigen3"
         "${MINGW_PACKAGE_PREFIX}-glog"
         "${MINGW_PACKAGE_PREFIX}-suitesparse")
checkdepends=("${MINGW_PACKAGE_PREFIX}-gflags")
source=("${url}${_realname}-${pkgver}.tar.gz"
        "${_realname}-1.13.0-CMakefiles.patch"
        "${_realname}-1.13.0-fix-testcode-failed.patch")
sha256sums=('10298a1d75ca884aa0507d1abb0e0f04800a92871cd400d4c361b56a777a7603'
            '608c8e1ec137d391a4f4367365400214054f44657a17c8231280d731210732c9'
            '8a4a67ddceef26924b10cf3576d47aadf2d789c8e88fa5f18b7ec7bd60ed3561')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "../${_realname}-1.13.0-CMakefiles.patch"
  patch -Np1 -i "../${_realname}-1.13.0-fix-testcode-failed.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=YES \
    "../${_realname}-${pkgver}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
